package com.proj.controller;

import com.proj.bean.User;
import com.proj.service.IManagerService;
import com.proj.util.LayData;
import com.proj.util.Page;
import com.proj.util.SYS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("manager")
public class ManagerController {

    @Autowired
    IManagerService managerService;

    @ResponseBody
    @RequestMapping("commonList")
    public LayData commonUsers(Page page, String text){
        List<User> users = managerService.commonUsers(page,text);
        int count=managerService.commoncount(text);
        return new LayData(count, users);
    };

    @ResponseBody
    @RequestMapping("AllList")
    public LayData AllUsers(Page page, String text, HttpSession session){
        int id=((User) session.getAttribute(SYS.SYSTEM_LOGIN_ADMIN)).getId();
        List<User> users = managerService.getAllUsers(id,page,text);
        int count=managerService.getAllCount(text);
        return new LayData(count, users);
    };
    @ResponseBody
    @RequestMapping("powerexchange")
    public int powerexchange(int id,HttpSession session){
        int me=((User) session.getAttribute(SYS.SYSTEM_LOGIN_ADMIN)).getId();
        if(id==me){
            return 0;
        }
        return managerService.powerexchange(id);
    };

    @ResponseBody
    @RequestMapping("editUser")
    public int editUser(User user){
        return managerService.editUser(user);
    };

    @ResponseBody
    @RequestMapping("chongzhi")
    public int chongzhi(int userid){
        return managerService.chongzhi(userid);
    };



}
